//
//  ChooseBankView.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/11/8.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "ChooseBankView.h"
#import "BankCell.h"


@implementation ChooseBankView

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupView];
}

- (void)setupView
{
    self.tableview = [[UITableView alloc]init];
    [self.bottomView addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(50);
        make.left.right.equalTo(self.bottomView);
        make.height.offset(333 - 50 - 60);
    }];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.rowHeight = 45;
    [self.tableview registerNib:[UINib nibWithNibName:@"BankCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    self.backgroundColor = [UIColor clearColor];
    self.tableview.tableFooterView = [UIView new];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BankCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    BindBankModel * model = self.dataArr[indexPath.row];
    cell.bankNameLaebl.text = model.bank_name;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    BankCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.selectBtn.selected = YES;
    BindBankModel * model = self.dataArr[indexPath.row];
    if (self.stringBlock) {
        self.stringBlock(model);
    }
    // 把index传出去  对应model中的数据就拿到了是哪个银行
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self removeFromSuperview];
    });
    
}

- (IBAction)removeViewAction:(UIButton *)sender {
    
    [sender removeFromSuperview];
    [self removeFromSuperview];
}

@end
